# 排序
from os import name
from xlwings import main

# 列表排序
def degree_order(degree):
    if degree == '学士':
        return 0
    elif degree == '硕士':
        return 1
    elif degree == '博士':
        return 2
    elif degree == '圣斗士':
        return 3
    else:
        return -1

# 针对列表的排序，样式：['张三','学士']
def degree_order_list(degree_list):
    degree = degree_list[1]
    if degree == '学士':
        return 0
    elif degree == '硕士':
        return 1
    elif degree == '博士':
        return 2
    elif degree == '圣斗士':
        return 3
    else:
        return -1

# 优雅地写代码，字典代替判断条件
dic = {'学士':0,'硕士':1,'博士':2,'圣斗士':3}
def degree_order_list_grace(degree_list):
    element_value = degree_list[1]
    return dic[element_value]

if __name__ == '__main__':
    
    arr01 = [-3, 1, 209, -48]
    # arr01.sort()
    arr01.sort(key = abs) # key参数为函数，写函数名，不加括号，abs()
    print(arr01)

    arr02 = [842, -32, 434, 39130]
    sorted(arr02)  # 不改变原始list
    print(arr02)
    # test01
    names = ['学士','硕士','学士','博士','圣斗士','学士', '学士', '博士', '学士','硕士','someone -1']
    names.sort(key = degree_order, reverse=True)
    print(names)
    # test02
    names02 = [['张三', '学士'],['赵六', '学士'],['茄子煲', '学士'],['哼哈', '学士'],['无双', '硕士'],['李四', '博士'],['小叮当', '博士']]
    print(type(names02))
    # test03
    print(names02)
    names02.sort(key = degree_order_list, reverse=True)
    print(names02)
    #test03
    names02.sort(key = degree_order_list_grace, reverse=True)
    print(names02)